﻿namespace Data
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using PivotCollectionTools.Data;
    using PivotCollectionTools.Library;
    using PivotCollectionTools.Xml;

    /// <summary>
    /// Summary description for TestDrivenDevelopment
    /// </summary>
    [TestClass]
    public class TestDrivenDevelopment
    {
        public TestDrivenDevelopment()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void SaveTable()
        {
            var project = new PivotCollectionProject();
            PivotTable table = project.Table;
            
            // Add categories to the table similar to the pivot collection facetCategory.
            table.Categories.Add(new PivotTableCategory("Body Style", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Fuel", PivotTableCellType.Text));

            // These two are columns boud to a facetCategory
            table.AddColumn("Body Style", 2);
            table.AddColumn("Fuel");

            // Create a new data row.
            PivotTableRow newDataRow = table.NewRow();

            // Assign values to the cells of the data row.
            newDataRow.Cells["Image Location"].Value = @"c:\data\images\xyz.jpg";
            newDataRow.Cells["Name"].Value = "First Car";
            newDataRow.Cells["Href"].Value = "";
            newDataRow.Cells["Body Style"].Value = "Compact";
            newDataRow.Cells["Body Style 1"].Value = "SUV";
            newDataRow.Cells["Fuel"].Value = "Flex Capcitor";

            // Add another data row.
            PivotTableRow newDataRow1 = table.NewRow();
            newDataRow1.Cells["Image Location"].Value = @"c:\data\images\abc.jpg";
            newDataRow1.Cells["Name"].Value = "Second Car";
            newDataRow1.Cells["Href"].Value = "";
            newDataRow1.Cells["Body Style"].Value = "Suv";
            newDataRow1.Cells["Fuel"].Value = "Water";
            
            // Similate saving the data and closing the application.
            project.SaveProject("../../../CarCollection.dat");
            table.Clear();

            // Load the data back intto a table.
            project = PivotCollectionProject.LoadProject("../../../CarCollection.dat");
            table = project.Table;

            // Make sure the data saved is the data read.
            Console.Write(table.Categories.Count);
            Console.Write(table.DataRows[0].Cells["Image Location"].Value);

            var xmlBuilder = new PivotXmlBuilder()
            {
                ImageBase = "dsaf\\dsaf"
            };

            PivotXml xml = xmlBuilder.CreatePivotXml(table);
            xml.Name = "Car Collection";
            xml.WriteXml("../../../NewCxml.cxml");
            // Need to create a PivotXml object from the PivotTable
            // Add to the object the missing data for example the location of the DeepZoop
            // Name of the Collection, Copy Right, etc.
            // Also loop through the image file name in the PivotTable pass to Deep Zoom
            // As you loop through assign the Deep Zoom Image number to the 
            // xml.ItemList[0].Items[0].Image = "#0";
            // xml.ItemList[0].Items[0].Identifier = "0";

            // var converter = new ImageConverter(@"D:\Data\GymManager\SystemTesting\collection_images");
            // forach (var dataRow in table.DataRows)
            // {
            //    converter.ConvertImage(dataRow.Cells["Image Location"].Value);
            // }
            // DeepZoomCreator.CreateCollection(deepZoomFolder + "\\images", deepZoomFolder + "\\asdf.xml");
        }

        [TestMethod]
        public void TestStudentCollection()
        {
            var project = new PivotCollectionProject()
            {
                PublishFolder = "D:\\Data\\GymManager\\SystemTesting\\",
                ConvertedImageFolder = "deepzoom_images",
                DeepZoomCollectionName = "deepzoom",
                CollectionTitle = "Student Collection",
                PivotCollectionFileName = "students.cxml"
            };

            PivotTable table = project.Table;

            table.Categories.Add(new PivotTableCategory("Student Name", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Brith Date", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Full Age", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Age", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Address", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("City", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("State", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Zip", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Resp. Adult", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Class", PivotTableCellType.Text));
            
            table.AddColumn("Student Name");
            table.AddColumn("Brith Date");
            table.AddColumn("Full Age");
            table.AddColumn("Age");
            table.AddColumn("Address");
            table.AddColumn("City");
            table.AddColumn("State");
            table.AddColumn("Zip");
            table.AddColumn("Resp. Adult");
            table.AddColumn("Class", 9);

            PivotTableRow newRow;
            newRow = table.NewRow();
            newRow["Image Location"].Value = @"D:\data\GymManager\GymRecordImage\9b6ed7a5-1ec4-4ccb-8234-000d4d6c419d.jpg";
            newRow["Name"].Value = "ALLISON BANNO";
            newRow["Student Name"].Value = "ALLISON BANNO";
            newRow["Brith Date"].Value = "11/09/06";
            newRow["Full Age"].Value = "3";
            newRow["Age"].Value = "3";
            newRow["Address"].Value = "123 WHITE OAKS DR.";
            newRow["Class"].Value = "F02";
            newRow["Class 1"].Value = "F03";

            newRow = table.NewRow();
            newRow["Image Location"].Value = @"D:\data\GymManager\GymRecordImage\45503f3f-8c95-4fd8-8827-0035c56a7be5.jpg";
            newRow["Name"].Value = "EMILY BAKER";
            newRow["Student Name"].Value = "EMILY BAKER";
            newRow["Brith Date"].Value = "03/17/00";
            newRow["Full Age"].Value = "9 - 1/2";
            newRow["Age"].Value = "9";
            newRow["Address"].Value = "123 SAN REMO DR.";
            newRow["Class"].Value = "F03";

            var builder = new PivotCollectionBuilder(table);
            builder.CreateCollection(
                project.PublishFolder,
                project.ConvertedImageFolder,
                project.DeepZoomCollectionName,
                project.PivotCollectionFileName,
                project.CollectionTitle);

            // Simulate saving the data and closing the application.
            project.SaveProject("../../../StudentCollection.pvt");
            table.Clear();

            // Load the data back intto a table.
            project = PivotCollectionProject.LoadProject("../../../StudentCollection.pvt");
        }

        [TestMethod]
        public void CreateXml()
        {
            PivotTable table = new PivotTable();

            // This create a table category which is like a Facet Category.
            var category = new PivotTableCategory("Category One", PivotTableCellType.Text)
            {
                IsFilterVisible = true,
                IsMetadataVisible = true,
                IsWordWheelVisible = true
            };

            table.Categories.Add(category);

            // Add a column to the table in the Category One group.
            table.AddColumn("Category One");

            // Create a new row.
            PivotTableRow newRow = table.NewRow();

            // The DataRow provides more information about an item than what 
            // a Item object of the Xml.
            newRow["Image Location"].Value = @"D:\data\image\9b6ed7a5-1ec4-4ccb-8234-000d4d6c419d.jpg";
            newRow["Name"].Value = "Item";

            // This will be translated to a Facet of the item.
            newRow["Category One"].Value = "Value One";
           
            // Create a build which will build a Pivot Xml from
            // a PivotTable.
            var builder = new PivotXmlBuilder();

            // Set the properties for the Collection Xml.
            builder.CollectionTitle = "Car Collection";
            builder.ImageBase = "dzm\\dzm.dzc";

            // Create the PivtoXml object.
            PivotXml xml = builder.CreatePivotXml(table);
            xml.WriteXml("car.xml");
        }

        [TestMethod]
        public void TestStudentCollection2()
        {
            var project = new PivotCollectionProject()
            {
                PublishFolder = "D:\\Data\\GymManager\\SystemTesting\\",
                ConvertedImageFolder = "deepzoom_images",
                DeepZoomCollectionName = "deepzoom",
                CollectionTitle = "Student Collection",
                PivotCollectionFileName = "students.cxml"
            };

            PivotTable table = project.Table;

            table.Categories.Add(new PivotTableCategory("Student Name", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Brith Date", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Full Age", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Age", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Address", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("City", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("State", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Zip", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Resp. Adult", PivotTableCellType.Text));
            table.Categories.Add(new PivotTableCategory("Class", PivotTableCellType.Text));

            table.AddColumn("Student Name");
            table.AddColumn("Brith Date");
            table.AddColumn("Full Age");
            table.AddColumn("Age");
            table.AddColumn("Address");
            table.AddColumn("City");
            table.AddColumn("State");
            table.AddColumn("Zip");
            table.AddColumn("Resp. Adult");
            table.AddColumn("Class", 9);

            PivotTableRow newRow;
            newRow = table.NewRow();
            newRow["Image Location"].Value = @"D:\data\GymManager\GymRecordImage\9b6ed7a5-1ec4-4ccb-8234-000d4d6c419d.jpg";
            newRow["Name"].Value = "ALLISON BANNO";
            newRow["Student Name"].Value = "ALLISON BANNO";
            newRow["Brith Date"].Value = "11/09/06";
            newRow["Full Age"].Value = "3";
            newRow["Age"].Value = "3";
            newRow["Address"].Value = "123 WHITE OAKS DR.";
            newRow["Class"].Value = "F02";
            newRow["Class 1"].Value = "F03";

            newRow = table.NewRow();
            newRow["Image Location"].Value = @"D:\data\GymManager\GymRecordImage\45503f3f-8c95-4fd8-8827-0035c56a7be5.jpg";
            newRow["Name"].Value = "EMILY BAKER";
            newRow["Student Name"].Value = "EMILY BAKER";
            newRow["Brith Date"].Value = "03/17/00";
            newRow["Full Age"].Value = "9 - 1/2";
            newRow["Age"].Value = "9";
            newRow["Address"].Value = "123 SAN REMO DR.";
            newRow["Class"].Value = "F03";

            var builder = new PivotCollectionBuilder(table);
            builder.CreateCollection(
                project.PublishFolder,
                project.ConvertedImageFolder,
                project.DeepZoomCollectionName,
                project.PivotCollectionFileName,
                project.CollectionTitle);

            // Simulate saving the data and closing the application.
            project.SaveProject("../../../StudentCollection.pvt");
            table.Clear();

            // Load the data back intto a table.
            project = PivotCollectionProject.LoadProject("../../../StudentCollection.pvt");
        }
    }
}
